package com.pe.pgn.clubpgn.webapp.controller.variable;


import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.support.SessionStatus;
import com.pe.pgn.clubpgn.common.CLPConstantes;
import com.pe.pgn.clubpgn.domain.beans.BNVariablesSistema;
import com.pe.pgn.clubpgn.service.VariableGlobalService;
import com.pe.pgn.clubpgn.webapp.controller.BaseFormController;


@Controller
@RequestMapping("/variable/**")
public class VariableGlobalController extends BaseFormController {
	

	@Autowired 
	private VariableGlobalService variableGlobalservice;

					
	@RequestMapping(value = "/variableglobalform.html")
	public @ModelAttribute("variableGlobales") BNVariablesSistema mostrarVariables(
			Model model,HttpServletRequest request) {
		
		BNVariablesSistema variableGlobales= new BNVariablesSistema();

		variableGlobales=variableGlobalservice.obtenerVariables();
	
		return variableGlobales;

		
	}

	
	@RequestMapping(value = "/variableglobalform.html", method = RequestMethod.POST)
	public String obtenerVariables(
			@ModelAttribute("variableGlobales") BNVariablesSistema bnVariablesSistema,
			Model model,  SessionStatus status, HttpServletRequest request) {
		
		
			String res=variableGlobalservice.actualizarVariablesGlobales(bnVariablesSistema);
		
		if(res.equals(CLPConstantes.SUCCESS+"")){
			saveMessage(request, getText("common.added", request.getLocale()));
			return "redirect:variableglobalform.html";
			
		}else if(res.equals(CLPConstantes.ERROR+"")){
			saveError(request, getText("errors.general", request.getLocale()));
			return "redirect:variableglobalform.html";
		}
		
		return "redirect:variableglobalform.html";
		
		
	}
	

	
	

}
